//
//  Medium_MusicCD03_01.swift
//  TimMusic
//
//  Created by nkl on 2024/10/21.
//

import Foundation
import SwiftUI

struct Medium_MusicCD03_01: View {
    var model: ControlMusicModel
    var body: some View {
        ZStack {
            Image("medium_03_bg").resizable()
            HStack {
                if let data = model.imageData, let uiImage = UIImage(data: data) {
                    Image(uiImage: uiImage).resizable().frame(width: 100, height: 100).cornerRadius(8)
                } else {
                    Image("ic_small_placeholder").resizable().frame(width: 100, height: 100).cornerRadius(8)
                }
                Spacer()
                VStack {
                    Text(model.title)
                        .font(.system(size: 18).bold())
                        .foregroundColor(.white)
                        .lineLimit(1)
                        .multilineTextAlignment(.center)
                    Spacer().frame(height: 15)
                    Text(model.auth)
                        .font(.system(size: 14))
                        .foregroundColor(.white.opacity(0.4))
                        .lineLimit(1)
                        .multilineTextAlignment(.center)

                    Spacer().frame(height: 25)
                    HStack(spacing: 25) {
                        Image("ic_widget_last").resizable().frame(width: 32, height: 32)
                            .modifier(AppClickModifier(urlString: "timMusic://musicControl?option=\(OptionType.playlast.rawValue)", isStatic: model.isStatic))
                        if model.isPlay {
                            Image("ic_widget_pause").resizable().frame(width: 32, height: 32)
                                .modifier(AppClickModifier(urlString: "timMusic://musicControl?option=\(OptionType.pause.rawValue)", isStatic: model.isStatic))
                        } else {
                            Image("ic_widget_play").resizable().frame(width: 32, height: 32)
                                .modifier(AppClickModifier(urlString: "timMusic://musicControl?option=\(OptionType.play.rawValue)", isStatic: model.isStatic))
                        }
                        Image("ic_widget_next").resizable().frame(width: 32, height: 32)
                            .modifier(AppClickModifier(urlString: "timMusic://musicControl?option=\(OptionType.playnext.rawValue)", isStatic: model.isStatic))
                    }
                }
                Spacer()
            }.padding(.horizontal, 16)
        }
    }
}

#Preview {
    Medium_MusicCD03_01(model: .init(title: "", auth: "", imageData: nil, isPlay: false, isStatic: true))
}
